package com.example.su_shi_tan_core

import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.example.su_shi_tan_bas_lib.networking.RestClient
import com.example.su_shi_tan_core.arouter.AppARouterParams
import com.example.su_shi_tan_core.db.LogInTokenManager
import com.example.su_shi_tan_core.utils.HiDataBus

class AppUpDataWorker (context: Context, param: WorkerParameters) : Worker(context, param)  {

    override fun doWork(): Result {
        if (!LogInTokenManager.tokenManager.haveSignedIn()) return Result.success()
        RestClient.builder()
            .url(R.string.get_version_number)
            .success {
                HiDataBus.with<String>(AppARouterParams.AppUpDataParams)
                    .postStickyData(it)
            }.build().get()

        return Result.success()
    }
}